﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Regist : System.Web.UI.Page
{
    User user = new User();
    protected void Page_Load(object sender, EventArgs e)
    {
        rbtnAgree.Checked = true;
    }
    protected void btnCheck_Click(object sender, EventArgs e)
    {
        if (txtUserName.Text.Trim() == "")
        {
            Response.Write("<script language=javascript>alert('用户名为空！')</script>");
        }
        else
        {
            bool bIsExist = user.IsExist(txtUserName.Text);
            if (bIsExist == true)
            {
                Response.Write("<script language=javascript>alert('对不起，用户名已占用！')</script>");
            }
            else
            {
                Response.Write("<script language=javascript>alert('恭喜！可以使用！')</script>");
            }
        }
    }
    protected void btnRegist_Click(object sender, EventArgs e)
    {
        if (rbtnDisagree.Checked == true)
        {
            return;
        }
        if (rbtnAgree.Checked == true)
        {
            int iResult = user.AddUser(txtUserName.Text, txtNickName.Text,
                txtPwd.Text, txtEmail.Text, txtAddress.Text,
                txtHomePage.Text, DateTime.Now);
            if (iResult > 0)
            {
                Session.Add("UserName",txtUserName.Text);
                Response.Redirect("TopicList.aspx");
            }
            else
            {
                Response.Write("<script language=javascript>alert('注册失败！')</script>");
            }
        }
    }
}
